package com.example.gouwu2;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;

public class RegisterActivity extends AppCompatActivity {
    private EditText etZhanghao, etPassword;
    private Button btnRegister;
    private TextView tvLogin;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        // 初始化UI组件
        etZhanghao = findViewById(R.id.r_zhuce);
        etPassword = findViewById(R.id.r_pass);
        btnRegister = findViewById(R.id.btn);
        tvLogin = findViewById(R.id.r_login);

        // 注册按钮点击事件
        btnRegister.setOnClickListener(v -> {
            String inputAccount = etZhanghao.getText().toString().trim();
            String inputPassword = etPassword.getText().toString().trim();

            // 验证输入是否为空
            if (inputAccount.isEmpty() || inputPassword.isEmpty()) {
                Toast.makeText(RegisterActivity.this, "账号和密码不能为空", Toast.LENGTH_SHORT).show();
                return;
            }


            // 注册成功
            Toast.makeText(RegisterActivity.this, "注册成功", Toast.LENGTH_SHORT).show();

            // 跳转到登录页面，并传递注册的账号密码
            Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
            intent.putExtra("account", inputAccount);
            intent.putExtra("password", inputPassword);
            startActivity(intent);
            finish(); // 关闭注册页面
        });

        // 已有账号，跳转登录
        tvLogin.setOnClickListener(v -> {
            startActivity(new Intent(RegisterActivity.this, LoginActivity.class));
            finish();
        });
    }
}